Skip to content

FEAT: Add MathematicalAlphanumericConverter (mathematical_alphanumeric converter) - #4451

Open
Roman Lutz (romanlutz) wants to merge 8 commits into
microsoft:mainfrom
romanlutz:gap1-mathalnum
Open

Roman Lutz (romanlutz) wants to merge 8 commits into
microsoft:mainfrom
romanlutz:gap1-mathalnum

Conversation

@romanlutz

@romanlutz Roman Lutz (romanlutz) commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

Adds this converter as part of the gap-1 converter series (splitting the esoteric cipher / encoder set into per-converter and per-base PRs). Includes a unit test and garak Encoding-scenario registration; CI-validated locally.

Sibling PRs will be cross-linked once the series is open.

🤖 Generated with Claude Code

gap-1 converter series — splitting the esoteric cipher / encoder set into reviewable PRs (open each independently; they touch the same four registration files, so later ones rebase as earlier ones merge):

…c converter)

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Copilot AI balanced review requested due to automatic review settings November 19, 2026 23:37

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The paired notebook is missing the new import and demonstration and needs its cell and rendered output synchronized with the Python documentation example.

1 open issue
What changed in this PR

Adds MathematicalAlphanumericConverter to PyRIT’s text-conversion toolkit and registers it with the Garak Encoding scenario.

Changes:

  • Supports 13 Unicode styles, including reserved-code-point exceptions and word selection.
  • Exposes the converter through lazy exports and the Encoding scenario’s all selection, without changing defaults.
  • Adds mapping and identifier tests plus a Python documentation example.
File Description
tests/​unit/​scenario/​garak/​test_encoding.py Updates the technique count and non-default selection expectations.
tests/​unit/​registry/​converter_identifier_samples.py Adds style samples for identifier contract checks.
tests/​unit/​converter/​test_mathematical_alphanumeric_converter.py Tests mappings, validation, word selection, and identifiers.
pyrit/​scenario/​scenarios/​garak/​encoding.py Registers the new encoding technique and converter variant.
pyrit/​converter/​mathematical_alphanumeric_converter.py Implements styled Unicode conversion.
pyrit/​converter/​__init__.py Adds the public lazy export and typing import.
doc/​code/​converters/​1_text_to_text_converters.py Adds a converter usage example.

Review effort: Balanced

print("ROT13:", await ROT13Converter().convert_async(prompt=prompt)) # type: ignore
print("Base64:", await Base64Converter().convert_async(prompt=prompt)) # type: ignore
print("Base2048:", await Base2048Converter().convert_async(prompt=prompt)) # type: ignore
print("Mathematical alphanumeric:", await MathematicalAlphanumericConverter().convert_async(prompt=prompt)) # type: ignore

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Update the saved modality table too.

.github/instructions/converters.instructions.md:112 also requires the modality table to include new converters. The saved table in doc/code/converters/0_converters.ipynb does not list MathematicalAlphanumericConverter, so readers cannot find it there. Refresh that saved table as well as this paired example. The existing Python code discovers the converter; no manual table row is needed.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The source .py already has the import and convert_async example. Regenerating the paired 1_text_to_text_converters.ipynb (rendered cell output) and the saved modality table in 0_converters.ipynb requires running the credentialed docs-build pipeline (jupytext sync + execution), which isn't available in this environment. Leaving this open so those notebooks are refreshed in the docs build before merge.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Update: synced the import and demonstration into the paired 1_text_to_text_converters.ipynb inline (commit c4a8ea3), matching 1_text_to_text_converters.py — this is the preferred execution-free approach for import additions per docs.instructions.md.

Two parts still regenerate in the docs build rather than here:

  • The new cell's rendered output (the Mathematical alphanumeric: ... print) — the docs pipeline re-executes the notebook.
  • The modality table in 0_converters.ipynb — that table is the saved stdout of get_converter_modalities(), which already discovers the converter automatically; only its rendered output is stale. Hand-reproducing the exact pandas formatting risks a mismatch with the build output, so leaving it for the docs build.

Leaving open per the P3/non-blocking note above.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work on this. Handling the reserved "holes" in the Mathematical Alphanumeric block through _STYLE_EXCEPTIONS, and testing that no style emits an unassigned code point, is exactly the right approach. I read the diff but did not run the code or the tests, so these are review notes, not test results.

I spot-checked the base code points for all 13 styles and the exception tables (italic h; script B E F H I L M R e g o; fraktur C H I R Z; double-struck C H N P Q R Z) against my understanding of the Unicode chart, and they look right.

  1. Typing of style. style: str is validated at runtime, but a Literal[...] type (as Base32Converter in #4452 does for variant) would let type checkers and IDEs catch typos. The tuple of valid styles could still be derived from _STYLE_BASES.

  2. Normalization note. The docstring says the output can slip past filters that match on exact ASCII. It might be worth adding that NFKC normalization maps these characters back to plain ASCII, so a target that normalizes its input will undo the transform. That tells users what the converter actually tests.

  3. Line length. In tests/unit/scenario/garak/test_encoding.py the changed assertion assert all_names - default_names == {... "mathematical_alphanumeric"} looks like it comes to roughly 129 characters. If the repo's formatter limit is 120, ruff format or the lint step will want it wrapped.

  4. Scope of the scenario change. The technique is added to the Garak EncodingTechnique set as ALL-only, which bumps the technique count from 18 to 19 in the test. That matches how other non-Garak techniques such as bifid are handled, so I think it is fine, but it may help to mention in the PR description that this one has no Garak counterpart.

  5. Characters not covered. Digits for styles with no digit run, and the dotless ı / ȷ and Greek math letters, are left unchanged. The docstring already explains the digit case, so this is only a note.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please address the semantic test gap below and the existing paired-notebook synchronization concern. No incorrect production mapping was found; the new finding concerns regression coverage for the handwritten Unicode ranges.

Addresses review feedback on microsoft#4451: the assigned-codepoint test accepted an
incorrect represented letter (e.g. a one-off base shift making AZ normalize to
Ba). Add a per-style assertion that NFKC-normalizing the converted alphabet
restores the original ASCII, pinning the meaning of every mapped glyph.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
…ticalAlphanumeric)

The Encoding scenario's ALL aggregate now has 20 techniques; the scanner guide
still said 18 and ended at Bifid, omitting ColumnarTransposition (already on main)
and this PR's MathematicalAlphanumeric. Update both the paired .py and .ipynb.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Automated review completed. No blocking concerns remain. This review records source coverage; merging is handled separately.

[P3] inline:4636592003: P2 -> P3: the paired notebook omits both the mathematical import and demonstration, so readers miss the new example and its output. It does not introduce a dangling call, wrong mathematical result or broken supported workflow. Keep the notebook synchronization correction open; a missing example alone is a nonblocking documentation issue.

[P3] inline:4645659734: P2 -> P3: the saved overview modality table omits the converter, reducing documentation discoverability. Its get_converter_modalities() generator and public export are correct; runtime registration and modality behavior are not broken. Refresh saved output through existing discovery. This useful extension of root 4636592003 remains unfixed.

[P3] local:4451-existing-notebook-example-sync: P2 -> P3, still supported and unfixed: synchronize the missing notebook import/example/output and refresh the saved modality row. This is the local alias of roots 4636592003 and 4645659734, not another defect. The omissions reduce documentation completeness and discoverability without incorrect executable guidance, runtime failure or lasting structural cost; instruction noncompliance alone did not justify P2.

# Conflicts:
#	doc/scanner/garak.ipynb
#	doc/scanner/garak.py
#	pyrit/scenario/scenarios/garak/encoding.py
#	tests/unit/scenario/garak/test_encoding.py
…rters notebook

Add the import and demonstration line to the paired .ipynb so it matches
1_text_to_text_converters.py, addressing the notebook-synchronization review
comment. Inline edit per docs.instructions.md (preferred approach for imports;
no execution needed). Rendered output refreshes in the docs build.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants